<template>
  <div class="">
    <!-- app-container -->
    <div class="head">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="" prop="orderCardActivityNamePhone">
          <el-input
            v-model="queryParams.orderCardActivityNamePhone"
            placeholder="订单编号、卡名称、活动名称、姓名、手机号"
            clearable
            style="width: 340px"
          />
        </el-form-item>
        <el-form-item label="交易时间：" prop="date">
          <el-date-picker v-model="date" type="daterange" value-format="yyyy-MM-dd" size="small" range-separator="至" 
            start-placeholder="开始日期" end-placeholder="结束日期" >
          </el-date-picker>
        </el-form-item> 
        <el-form-item label="订单状态：" prop="orderStatus">
          <el-select
            v-model="queryParams.orderStatus"
            filterable
            placeholder="请选择"
            clearable
            style="width: 240px"
          >
            <el-option
              v-for="dict in statusList"
              :key="dict.id"
              :label="dict.value"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="发行方：" prop="issuerId">
          <el-select
            v-model="queryParams.issuerId"
            filterable
            placeholder="请选择"
            clearable
            style="width: 240px"
          >
            <el-option
              v-for="dict in issuerSelectList"
              :key="dict.id"
              :label="dict.name"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="发行店铺：" prop="shopId">
          <el-select
            v-model="queryParams.shopId"
            filterable
            placeholder="请选择"
            clearable
            style="width: 240px"
          >
            <el-option
              v-for="dict in merchantList"
              :key="dict.id"
              :label="dict.value"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <div class="listBox_head" style="margin-bottom: 14px;">
        <export-excel-button title="订单记录" action="/pop/activity/order/export" :params="ExportParams" />
      </div>
      <el-table v-loading="loading" :data="tabList" stripe border>
        <el-table-column
          label="序号"
          align="center"
          type="index"
          width="64px"
        />
        <el-table-column
          label="订单编号"
          align="center"
          prop="orderId"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="交易时间"
          align="center"
          prop="orderTime"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="活动名称"
          align="center"
          prop="activityName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="卡名称"
          align="center"
          prop="cardName"
          :show-overflow-tooltip="true"
          width="150px"
        />
        <el-table-column
          label="发行方"
          align="center"
          prop="issuerName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="发行店铺"
          align="center"
          prop="shopName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="姓名"
          align="center"
          prop="customerName"
          :show-overflow-tooltip="true"
          width="150px"
        />
        <el-table-column
          label="手机号"
          align="center"
          prop="iphone"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="交易金额"
          align="center"
          prop="orderMoney"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="抵扣积分"
          align="center"
          prop="integral"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="实付金额"
          align="center"
          prop="payMoney"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="订单状态"
          align="center"
          prop="orderStatus"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <dict-tag :options="statusList" :value="scope.row.orderStatus" />
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      ></pagination>
    </div>
    <Dialog
      :id="dialogId"
      :pathType="pathType"
      v-bind="$attrs"
      v-if="dialogVisible"
      :visible.sync="dialogVisible"
      @success="_handleSuccess"
    >
    </Dialog>
  </div>
</template>
  
  <script>
import {
  orderList,
} from "@/api/consumeMiningManagement/popupActivity";
import {
    issuerSelectList,
  } from "@/api/equityManager/equityCard";
  import {
    shopSelect,
  } from "@/api/merchantsNFR/nfrIssue";
import ExportExcelButton from "@/components/ExportExcelButton/index";
import { string } from 'jszip/lib/support';

export default {
  name: "",
  components: {
    ExportExcelButton
  },
  
  data() {
    
    return {
      dialogId: "",
      dialogVisible: false,
      // 遮罩层
      loading: false,
      // 导出遮罩层
      // 总条数
      total: 0,
      statusList: [], //状态字典数组

      //表格数据
      tabList: [],
      pathType: "add",
      // 查询参数
      queryParams: {
        startDate: '',
        endDate: '',
        issuerId: '',//发行方
        orderStatus: '',//订单状态
        shopId: '',//发行店铺
        pageNum: 1,
        pageSize: 10,
        orderCardActivityNamePhone: "", //活动名称
      },
      date: [],
      issuerSelectList: [],
      merchantList: [],
    };
  },
  computed: {
      ExportParams() {
        const params = {
          ...this.queryParams,
        };
        return params;
      },
    },
  created() {
    this.getissuerSelect()
    this.getShop()

    this.getStatusList();
    this.getList();
  },
  methods: {
     //获取店铺下拉
     getShop() {
        shopSelect().then(res => {
          this.merchantList = res.result
        })
      },
    //获取发行方列表
    getissuerSelect() {
        let data = {}
        issuerSelectList(data).then(res => {
          this.issuerSelectList = res.result
        }).catch(() => {

        });
        // .finally(() => {

        // });
      },
    //获取活动状态字典
    getStatusList() {
      var dictType = "shenye_pop_activity_order_status";
      this.$getSelectList(dictType)
        .then((res) => {
          var arr = [
            {
              id: "",
              value: "全部",
            },
          ];
          this.statusList = arr.concat(res.result[0].dictList);
        })
        .finally(() => {});
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      if (this.date) {
        this.queryParams.startDate = this.date[0]
        this.queryParams.endDate = this.date[1]
      }
      orderList(this.queryParams).then((response) => {
        response.result.records.forEach(item => {
          for (var key in item) {
            if (!item[key]) {
              item[key] = "-";
            }
          }
        });
        
        this.tabList = response.result.records;
        this.total = response.result.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.queryParams = {
        startDate: '',
        endDate: '',
        issuerId: '',//发行方
        orderStatus: '',//订单状态
        shopId: '',//发行店铺
        pageNum: 1,
        pageSize: 10,
        orderCardActivityNamePhone: "", //活动名称
      };
      // this.resetForm("form");
      this.date = []
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      this.reset();
      this.handleQuery();
    },
    
  },
};
</script>
  <style scoped>
.head {
  box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
  background-color: #fff;
  border-radius: 8px;
  padding: 20px 20px 0;
}

.listBox {
  box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
  background-color: #fff;
  border-radius: 8px;
  padding: 20px 20px;
  margin-top: 10px;
}

.listBox_head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.img_box {
  width: 100px;
  height: 80px;
  border-radius: 4px;
}
</style>
  